import java.awt.Image;
import java.awt.Rectangle;

import javax.swing.ImageIcon;

public class Bugger {

	// TODO Get final values for these
	public static final int IMAGE_WIDTH = 41, IMAGE_HEIGHT = 68, PURPLE = 0,
			GREEN = 1;

	private final String PICTURE_BUGGER_GREEN = "BuggerGreen.png",
			PICTURE_BUGGER_PURPLE = "BuggerPurple.png",
			PICTURE_BUGGER_MINI = "BuggerMini.png";

	private Image image, miniImage;

	private int x, y; // Position
	private int velocity;
	private int vMultiplier = 1; // Velocity multiplier, used during space bar
									// acceleration
	private int width, height;
	private boolean visible;

	public Bugger(int xInitial, int yInitial, int velocity, int imageColor) {
		x = xInitial;
		y = yInitial;
		this.velocity = velocity;

		visible = true;
		
		ImageIcon ii = null;

		if (imageColor == PURPLE) {
			ii = new ImageIcon(this.getClass().getResource(
					PICTURE_BUGGER_PURPLE));
			image = ii.getImage();
		} else if (imageColor == GREEN) {
			ii = new ImageIcon(this.getClass().getResource(
					PICTURE_BUGGER_GREEN));
			image = ii.getImage();
		}

		ii = new ImageIcon(this.getClass().getResource(PICTURE_BUGGER_MINI));
		miniImage = ii.getImage();

		width = image.getWidth(null);
		height = image.getHeight(null);
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public int getImageWidth() {
		return width;
	}

	public int getImageHeight() {
		return height;
	}

	public Rectangle getBounds() {
		return new Rectangle(x + width/2, y + height/2, width - 20, height - 20);
	}

	public Image getImage() {
		return image;
	}

	public Image getMiniImage() {
		return miniImage;
	}

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}
	
	public void setToNormalSpeed() {
		vMultiplier = 1;
	}

	// Increase the velocity multiplier of the Bugger
	// TODO turn this into a function of time, the longer space bar gets held
	// down, higher vMultiplier
	public void accelerate() {
		vMultiplier = 2;
	}

	public void move() {
		y += velocity * vMultiplier;

		if (y > EndersGame.WINDOW_HEIGHT * EndersGame.BOARD_HEIGHT) {
			visible = false;
		}
	}
}
